import requests

#登录
ip='http://192.168.40.128:8080'
# url='http://192.168.40.128:8080/login'
mydata={'username':'admin','password':'123456'}
# r=requests.post('http://192.168.40.128:8080/login',data=mydata)
r=requests.post(f'{ip}/login',data=mydata)

# print(r)
#打印响应
#json获取的内容是由单引号引起的
# print(r.json())
#text获取的内容是用双引号引起的
# print(r.text)
#content获取的内容开头有个b，中文是乱码
# print(r.content)


#提取token
myjson=r.json()
token=myjson['Admin-Token']
# print(token)
#引token
myheader={'Admin-Token':token}

#日志
#文件上传-新增/修改日志接口
filew=r'D:\RCe\Rce\RCeJieKouzdh\datas\1.jpg'
zengdata={'type':'img'}
zengfile={'file':('1.jpg',
                  open(filew,'rb'),
                  'image/jpeg')}
z=requests.post(f'{ip}/file/upload',
                data=zengdata,
                files=zengfile,
                headers=myheader)
print(z.json())


#新增日志
zengjson={
  "categoryId": "1",
  "content": "cccccc",
  "tomorrow": "aaaaaa",
  "question": "bbbbbbb",
  "batchId": "721dcd430a96db886ae30343b789e26d",
  "sendUserIds": "",
  "sendDeptIds": "",
  "customerIds": "",
  "contactsIds": "",
  "businessIds": "",
  "contractIds": ""
}
xz=requests.post(f'{ip}/OaLog/addOrUpdate',json=zengjson,headers=myheader)
print(xz.json())

#修改日志
xiujson={
  "logId": 2,
  "categoryId": "1",
  "content": "今天的修改",
  "tomorrow": "修改修改",
  "question": "嗷嗷嗷啊吖",
  "batchId": "721dcd430a96db886ae30343b789e26d",
  "sendUserIds": "",
  "sendDeptIds": "",
  "customerIds": "",
  "contactsIds": "",
  "businessIds": "",
  "contractIds": ""
}
xiu=requests.post(f'{ip}/OaLog/addOrUpdate',json=xiujson,headers=myheader)
print(xiu.json())
#获取日志列表
huojson={
  "page": 1,
  "limit": 50,
    "by":1
}
huo=requests.post(f'{ip}/OaLog/queryList',json=huojson,headers=myheader)
print(huo.json())


#获取logid
#获取1个logid
rlist=huo.json()['data']['list'][0]['logId']
print(rlist)
#获取全部logid
# rlist=huo.json()['data']['list']
# ls=[]
# for i in rlist:
#     ls.append(i['logId'])
# print(ls)


#删除日志--删除单个
sdata={'logId':rlist}
s=requests.post(f'{ip}/OaLog/deleteById',data=sdata,headers=myheader)
print(s.json())
#删除日志--删除多个
# sdata={'logId':ls}
# s=requests.post(f'{ip}/OaLog/deleteById',data=sdata,headers=myheader)
# print(s.json())



















